
const {ccclass, property} = cc._decorator;
import Global = require("./GlobalEvents");

@ccclass
export default class NewClass extends cc.Component {    

    @property(cc.Button)
    btnplay: cc.Button = null;

    @property(cc.Button)
    btnsound: cc.Button = null;

    @property(cc.Button)
    btnmusic: cc.Button = null;

    @property(cc.Button)
    btntotal: cc.Button = null;

    @property(cc.SpriteFrame)
    soundenbPic: cc.SpriteFrame = null;

    @property(cc.SpriteFrame)
    sounddisPic: cc.SpriteFrame = null;

    @property(cc.SpriteFrame)
    musicenbPic: cc.SpriteFrame = null;

    @property(cc.SpriteFrame)
    musicedisPic: cc.SpriteFrame = null;

    @property({
        type: cc.AudioClip
    })
    buttonAudio = null;
    // LIFE-CYCLE CALLBACKS:

    onLoad () {

        var self = this;
        //声音 
        if(self.btnsound!=null){
                   
            self.btnsound.node.on(cc.Node.EventType.TOUCH_START, function (event) {
                //console.log(' TOUCH_START');
                if(Global.isSound==0){}            
                else            
                {                
                    cc.audioEngine.play(self.buttonAudio, false, 1);            
                }
            });
            self.btnsound.node.on(cc.Node.EventType.TOUCH_MOVE, function (event) {
                //console.log(' TOUCH_MOVE');
                self.btnsound.getComponent(cc.Animation).play();           
                
            });
            self.btnsound.node.on(cc.Node.EventType.TOUCH_END, function (event) {
                //console.log(' TOUCH_END');
                self.btnsound.getComponent(cc.Animation).stop();
                //换图片
                if(Global.isSound==1){
                    //Global.isSound = 0;  
                    self.btnsound.getComponent(cc.Sprite).spriteFrame = self.sounddisPic;
                }
                else{
                    //Global.isSound = 1;
                    self.btnsound.getComponent(cc.Sprite).spriteFrame = self.soundenbPic;
                }
                
            });
            self.btnsound.node.on(cc.Node.EventType.TOUCH_CANCEL, function (event) {
                //console.log(' TOUCH_CANCEL');
                self.btnsound.getComponent(cc.Animation).stop();

            });
            self.btnsound.node.on(cc.Node.EventType.MOUSE_ENTER, function (event) {
                //console.log(' MOUSE_ENTER');
                self.btnsound.getComponent(cc.Animation).play();
            });
            self.btnsound.node.on(cc.Node.EventType.MOUSE_LEAVE, function (event) {
                //console.log(' MOUSE_LEAVE');
                self.btnsound.getComponent(cc.Animation).stop();
                

            });
            self.btnsound.node.on(cc.Node.EventType.MOUSE_DOWN, function (event) {
                //console.log(' MOUSE_DOWN');
                if(Global.isSound==0){}            
                else            
                {                
                    cc.audioEngine.play(self.buttonAudio, false, 1);            
                }
            });
        }
        //播放
        if(self.btnplay!=null){
            
            self.btnplay.node.on(cc.Node.EventType.TOUCH_START, function (event) {
                //console.log(' TOUCH_START');
                if(Global.isSound==0){}            
                else            
                {                
                    cc.audioEngine.play(self.buttonAudio, false, 1);            
                }
            });

            self.btnplay.node.on(cc.Node.EventType.TOUCH_MOVE, function (event) {
                //console.log(' TOUCH_MOVE');
                self.btnplay.getComponent(cc.Animation).play();
            });

            self.btnplay.node.on(cc.Node.EventType.TOUCH_END, function (event) {
                //console.log(' TOUCH_END');
                self.btnplay.getComponent(cc.Animation).stop();
            });

            self.btnplay.node.on(cc.Node.EventType.TOUCH_CANCEL, function (event) {
                //console.log(' TOUCH_CANCEL');
                self.btnplay.getComponent(cc.Animation).stop();

            });

            self.btnplay.node.on(cc.Node.EventType.MOUSE_ENTER, function (event) {
                //console.log(' MOUSE_ENTER');
                self.btnplay.getComponent(cc.Animation).play();
            });

            self.btnplay.node.on(cc.Node.EventType.MOUSE_LEAVE, function (event) {
                //console.log(' MOUSE_LEAVE');
                self.btnplay.getComponent(cc.Animation).stop();

            });
            self.btnplay.node.on(cc.Node.EventType.MOUSE_DOWN, function (event) {
                //console.log(' MOUSE_DOWN');
                if(Global.isSound==0){}            
                else            
                {                
                    cc.audioEngine.play(self.buttonAudio, false, 1);            
                }
            });
        }
        //音乐
        if(self.btnmusic!=null){
            
            self.btnmusic.node.on(cc.Node.EventType.TOUCH_START, function (event) {
                //console.log(' TOUCH_START');
                if(Global.isSound==0){}            
                else            
                {                
                    cc.audioEngine.play(self.buttonAudio, false, 1);            
                }
            });

            self.btnmusic.node.on(cc.Node.EventType.TOUCH_MOVE, function (event) {
                //console.log(' TOUCH_MOVE');
                self.btnmusic.getComponent(cc.Animation).play();
            });

            self.btnmusic.node.on(cc.Node.EventType.TOUCH_END, function (event) {
                //console.log(' TOUCH_END');
                self.btnmusic.getComponent(cc.Animation).stop();
                //换图片
                if(Global.isMusic==1){
                    //Global.isSound = 0;  
                    self.btnmusic.getComponent(cc.Sprite).spriteFrame = self.musicedisPic;
                }
                else{
                    //Global.isSound = 1;
                    self.btnmusic.getComponent(cc.Sprite).spriteFrame = self.musicenbPic;
                }
            });

            self.btnmusic.node.on(cc.Node.EventType.TOUCH_CANCEL, function (event) {
                //console.log(' TOUCH_CANCEL');
                self.btnmusic.getComponent(cc.Animation).stop();

            });

            self.btnmusic.node.on(cc.Node.EventType.MOUSE_ENTER, function (event) {
                //console.log(' MOUSE_ENTER');
                self.btnmusic.getComponent(cc.Animation).play();
            });

            self.btnmusic.node.on(cc.Node.EventType.MOUSE_LEAVE, function (event) {
                //console.log(' MOUSE_LEAVE');
                self.btnmusic.getComponent(cc.Animation).stop();
                
            });
            self.btnmusic.node.on(cc.Node.EventType.MOUSE_DOWN, function (event) {
                //console.log(' MOUSE_DOWN');
                if(Global.isSound==0){}            
                else            
                {                
                    cc.audioEngine.play(self.buttonAudio, false, 1);            
                }
            });
        }
        //排行榜
        if(self.btntotal!=null){
            
            self.btntotal.node.on(cc.Node.EventType.TOUCH_START, function (event) {
                //console.log(' TOUCH_START');
                if(Global.isSound==0){}            
                else            
                {                
                    cc.audioEngine.play(self.buttonAudio, false, 1);            
                }
            });

            self.btntotal.node.on(cc.Node.EventType.TOUCH_MOVE, function (event) {
                //console.log(' TOUCH_MOVE');
                self.btntotal.getComponent(cc.Animation).play();
            });

            self.btntotal.node.on(cc.Node.EventType.TOUCH_END, function (event) {
                //console.log(' TOUCH_END');
                self.btntotal.getComponent(cc.Animation).stop();
            });

            self.btntotal.node.on(cc.Node.EventType.TOUCH_CANCEL, function (event) {
                //console.log(' TOUCH_CANCEL');
                self.btntotal.getComponent(cc.Animation).stop();

            });

            self.btntotal.node.on(cc.Node.EventType.MOUSE_ENTER, function (event) {
                //console.log(' MOUSE_ENTER');
                self.btntotal.getComponent(cc.Animation).play();
            });

            self.btntotal.node.on(cc.Node.EventType.MOUSE_LEAVE, function (event) {
                //console.log(' MOUSE_LEAVE');
                self.btntotal.getComponent(cc.Animation).stop();

            });
            self.btntotal.node.on(cc.Node.EventType.MOUSE_DOWN, function (event) {
                //console.log(' MOUSE_DOWN');
                if(Global.isSound==0){}            
                else            
                {                
                    cc.audioEngine.play(self.buttonAudio, false, 1);            
                }
            });
        }        
    }

    //start () {}

    // update (dt) {}
}
